package com.xusheng.cli.controller.user;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xusheng.cli.common.annotation.OperationLogAnno;
import com.xusheng.cli.common.base.MyPage;
import com.xusheng.cli.common.base.Result;
import com.xusheng.cli.common.enums.OperationType;
import com.xusheng.cli.common.validation.Save;
import com.xusheng.cli.common.validation.Update;
import com.xusheng.cli.entity.frontUserModule.VipConfig;
import com.xusheng.cli.service.VipConfigService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.List;

/**
 * 会员等级列表接口
 *
 * @author lyh
 * @since 2023-04-28 16:32:03
 */
@Validated
@RestController
@RequestMapping("/user/v1/vipConfig")
public class VipConfigController {
    /**
     * 服务对象
     */
    @Resource
    private VipConfigService vipConfigService;
     
     /**
     * 查询所有数据
     *
     * @param vipConfig 查询实体
     * @return 所有数据
     * @author lyh
     * @since 2023-04-28 16:32:03
     */
    @GetMapping("queryAll")
    public Result<List<VipConfig>> queryAll(VipConfig vipConfig) {
        return Result.success(vipConfigService.list(new QueryWrapper<>(vipConfig)));
    }

    /**
     * 分页查询所有数据
     *
     * @param page 分页对象
     * @param vipConfig 查询实体
     * @return 所有数据
     * @author lyh
     * @since 2023-04-28 16:32:03
     */
    @GetMapping("queryByPage")
    public Result<MyPage<VipConfig>> queryByPage(MyPage<VipConfig> page, VipConfig vipConfig) {
        return Result.success(vipConfigService.page(page, new QueryWrapper<>(vipConfig)));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     * @author lyh
     * @since 2023-04-28 16:32:03
     */
    @GetMapping("queryOne/{id}")
    public Result<VipConfig> selectOne(@PathVariable Serializable id) {
        return Result.success(vipConfigService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param vipConfig 实体对象
     * @return 新增结果
     * @author lyh
     * @since 2023-04-28 16:32:03
     */
    @PostMapping("insert")
    @OperationLogAnno(module = "模块", type = OperationType.CREATE, desc = "添加一条数据")
    public Result<Object> insert(@Validated(Save.class) @RequestBody VipConfig vipConfig) {
        return Result.isSuccess(vipConfigService.save(vipConfig));
    }

    /**
     * 修改数据
     *
     * @param vipConfig 实体对象
     * @return 修改结果
     * @author lyh
     * @since 2023-04-28 16:32:03
     */
    @PutMapping("update")
    @OperationLogAnno(module = "模块", type = OperationType.UPDATE, desc = "修改一条数据")
    public Result<Object> update(@Validated(Update.class) @RequestBody VipConfig vipConfig) {
        return Result.isSuccess(vipConfigService.updateById(vipConfig));
    }
    /**
     * 删除单条数据
     *
     * @param id 主键
     * @return 删除结果
     * @author lyh
     * @since 2023-04-28 16:32:03
     */
    @DeleteMapping("delete/{id}")
    @OperationLogAnno(module = "模块", type = OperationType.UPDATE, desc = "删除一条数据")
    public Result<Object> delete(@PathVariable Long id) {
        VipConfig vipConfig = new VipConfig();
        vipConfig.setId(id);
		return Result.isSuccess(vipConfigService.removeById(vipConfig));
    }
    /**
     * 批量删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     * @author lyh
     * @since 2023-04-28 16:32:03
     */
    @DeleteMapping("batchDelete")
    @OperationLogAnno(module = "模块", type = OperationType.UPDATE, desc = "批量删除数据")
    public Result<Object> batchDelete(@Validated @Size(min = 1, message = "缺少删除所需的id") @RequestParam("idList") List<Long> idList) {
		return Result.isSuccess(vipConfigService.batchDelete(idList, new VipConfig()));
    }
}

